<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <link rel="stylesheet" href="../public/css/basic.css"/>
    <link rel="stylesheet" href="../public/layui/css/layui.css"/>
    <link rel="stylesheet" href="../public/layui/css/modules/layer/default/layer.css"/>
    <link rel="stylesheet" href="../public/css/manage.css"/>
    <script src="../public/js/jquery-1.11.1.min.js"></script>
    <title></title>
    <style>

        body{min-width: 500px}
    </style>
</head>
<body>

<form action="" class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">区域名称</label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入区域名称" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div style="height: 60px">
            <label class="layui-form-label" ><button type="button" class="layui-btn" id="up-pic">上传区域实景图片</button></label>

        </div>
        <div class="layui-input-block ">
            <img class="layui-upload-img" id="pic">
            <p id="errorText"></p>
        </div>
    </div>
    <div class="but1-mid">
        <button class="layui-btn bc">保存</button>
    </div>

</form>

<script src="../public/layui/layui.js"></script>
<script>
    layui.use('upload', function(){
        var $ = layui.jquery
                ,upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#up-pic'
            ,url: '/upload/'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#pic').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#errorText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });

    });



//获取实际图片宽高

    $(".bc").click(function(){
        var img = new Image();
        img.src =$('#pic').attr("src") ;
        var w = img.width;
        var h = img.height;
        var pic =[w,h]
        alert(pic);

    })
</script>

</body>
</html>